import {
	createRouter,
	createWebHistory,
	createWebHashHistory
} from 'vue-router'
const routes = [{
		path: '/',
		component: () => import("@/view/home/home.vue"),
		hidden: true,
		meta: {
			id: 0,
			name: '网站首页'
		}
	},
	{
		path: '/home',
		name: 'home',
		component: () => import("@/view/home/home.vue"),
		hidden: true,
		meta: {
			id: 0,
			name: '网站首页'
		}
	},
	{
		path: '/login',
		name: 'login',
		component: () => import("@/view/login/login.vue"),
		hidden: true,
		meta: {
			id: 2,
			name: '登录'
		}
	},
	{
		path: '/science',
		name: 'science',
		component: () => import("@/view/science/science.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '科技培训'
		}
	},
	{
		path: '/apply',
		name: 'apply',
		component: () => import("@/view/science/apply.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '科技培训'
		}
	},
	{
		path: '/application',
		name: 'application',
		component: () => import("@/view/science/application.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '科技培训'
		}
	},

	{
		path: '/classRoom',
		name: 'classRoom',
		component: () => import("@/view/classRoom/classRoom.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '三农课堂'
		}
	},
	{
		path: '/classDetail',
		name: 'classDetail',
		component: () => import("@/view/classRoom/classDetail.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '三农课堂',
			type:'islog'
		}
	},

	{
		path: '/thinkTank',
		name: 'thinkTank',
		component: () => import("@/view/thinkTank/thinkTank.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '专家智库'
		}
	},
	{
		path: '/essay',
		name: 'essay',
		component: () => import("@/view/essay/essay.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '农技问答'
		}
	},
	{
		path: '/essayDetail',
		name: 'essayDetail',
		component: () => import("@/view/essay/essayDetail.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '问答详情'
		}
	},
	{
		path: '/search',
		name: 'search',
		component: () => import("@/view/search/search.vue"),
		hidden: true,
		meta: {
			id: 2,
			name: '搜索'
		}
	},
	{
		path: '/popularize',
		name: 'popularize',
		component: () => import("@/view/popularize/popularize.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '科技成果'
		}
	},
	{
		path: '/newsDetail',
		name: 'newsDetail',
		component: () => import("@/view/news/newsDetail.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '新闻详情'
		}
	},
	{
		path: '/newsList',
		name: 'newsList',
		component: () => import("@/view/news/newsList.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '新闻资讯'
		}
	},
	
	{
		path: '/taskCenter',
		name: 'taskCenter',
		component: () => import("@/view/taskCenter/taskCenter.vue"),
		hidden: true,
		meta: {
			id: 1,
			name: '任务中心',
			type:'islog'
		}
	},
	{
		path: '/userCenter',
		name: 'userCenter',
		component: () => import("@/view/userCenter/userCenter.vue"),
		hidden: true,
		meta: {
			id: 2,
			name: '个人中心',
			type:'islog'
		},
		children: [{
				path: '/leaveList',
				name: 'leaveList',
				component: () => import("@/view/userCenter/leaveList.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '请假申请',
					icon1:1
				},
			},
			{
				path: '/certificate',
				name: 'certificate',
				component: () => import("@/view/userCenter/certificate.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '我的证书',
					order:2
				},
			},
			{
				path: '/study',
				name: 'study',
				component: () => import("@/view/userCenter/study.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '我的学习',
					order:3,
					type:'islog'
				}
			},
			{
				path: '/project',
				name: 'project',
				component: () => import("@/view/userCenter/project.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '我的创业项目',
					order:4
				}
			},
			{
				path: '/information',
				name: 'information',
				component: () => import("@/view/userCenter/information.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '报名信息',
					order:5
				}
			},
			{
				path: '/message',
				name: 'message',
				component: () => import("@/view/userCenter/message.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '消息通知',
					order:6
				}
			},
			{
				path: '/myCourses',
				name: 'myCourses',
				component: () => import("@/view/userCenter/myCourses.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '我的课程',
					order:6
				}
			},
			
			{
				path: '/callCenter',
				name: 'callCenter',
				component: () => import("@/view/userCenter/callCenter.vue"),
				hidden: true,
				meta: {
					id: 2,
					name: '客服中心',
					order:7
				}
			}
			
			
		]
	},



]
const router = createRouter({
	history: createWebHashHistory(),
	routes
})

router.beforeEach((to,from,next)=> {
	if(!localStorage.getItem('userUuid')){
		if(to.meta.name == '登录' || to.meta.name == '三农课堂'){
			next()
		}else{
			if(to.meta.type == 'islog'){
				ElMessage.error('请先登录')
				next({
				    path: '/home',
				});
				return;
			}else{
				next()
			}
		}
		
	}else{
		next()
	}
	// if(to.meta.name == 'Space' || to.meta.name == 'Exams'){
	// 	if(localStorage.getItem('username')){
	// 		next()
	// 	}else{
	// 		ElMessage.error('请先登录')
			
	// 		// next({
	// 		//     path: '/home',
	// 		// });

	// 		return;
	// 	}
	// }else{
	// 	next()
	// }
})
export default router